// 引入库
const Koa = require('koa')
const serve = require('koa-static')

// 创建服务器
const app = new Koa()
// 提供静态文件服务
app.use(serve(__dirname + '/public'))

const proxy = require('koa2-proxy-middleware')

app.use(proxy({
  targets: {
    // (.*) means anything
    '/prod-api/(.*)': {
      target: 'http://ihrm-java.itheima.net/api', // 后端服务器地址
      changeOrigin: true,
      pathRewrite: {
        '/prod-api': ''
      }
    }
  }
}))
// 运行服务器
app.listen(3334, () => {
  console.log('开启服务器成功')
  console.log('http://localhost:3334')
})
